package org.ucas.faker.web.utils.feature;

import org.ucas.faker.web.entity.patents.Symbol;
import org.ucas.faker.web.model.KeywordNode;
import org.ucas.faker.web.utils.tech.PatentFeaturize;
import org.ucas.faker.web.utils.tech.PatentFeaturizeWithKeywordTree;
import org.ucas.faker.web.entity.patents.PatentFeature;
import org.ucas.faker.web.entity.patents.PatentWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class TechGenerator implements FeatureGenerator {

  @Override
  public void generate(PatentWrapper patent) {
    if (patent.getFeature() == null) patent.setFeature(new PatentFeature(patent.getId()));
    PatentFeature feature = patent.getFeature();
    String abstraction = patent.getContent().getAb();

    abstraction = abstraction.split("\\|")[0];
    //Map<String, String> tmp = PatentFeaturize.getInstance().featurizeAbstract(abstraction);
    
    Map<String, String> tmp = PatentFeaturize.getInstance().featurizeAbstractWithRegularRule(abstraction);
    //System.out.println("In TechGenerator\t#"+tmp.get(0)+"#");

    String branch = tmp.get("branch");
    if (branch != null && !"".equals(branch.trim()))
      for (String str : branch.split("#")) {
	      str = str.replace(" ", "");
	      if(str.trim().length()<1) continue;
        Symbol br = new Symbol();
        br.setKind(Symbol.Category.BRANCH);
        br.setOriginal(str);
        feature.getBr().add(br);
      }

    String effect = tmp.get("effect");
    if(effect != null && !"".equals(effect.trim()))
    for (String str : effect.split("#")) {
	      str = str.replace(" ", "");
	      if(str.trim().length()<1) continue;
      Symbol ef = new Symbol();
      ef.setKind(Symbol.Category.EFFECT);
      ef.setOriginal(str);
      feature.getEf().add(ef);
    }
    
//    System.out.println("***************"+branch);
//    System.out.println("***************"+effect);
  }

	@Override
	public void generate(PatentWrapper patent, PatentFeaturizeWithKeywordTree pf) {

	    if (patent.getFeature() == null) patent.setFeature(new PatentFeature(patent.getId()));
	    PatentFeature feature = patent.getFeature();
	    String abstraction = patent.getContent().getAb();


	    abstraction = abstraction.split("\\|")[0];	 
	    
	    Map<String, String> tmp = pf.featurizeAbstractWithRegularRule(abstraction);

	    String branch = tmp.get("branch");
	    if (branch != null && !"".equals(branch.trim()))
	      for (String str : branch.split("#")) {
		      str = str.replace(" ", "");
		      if(str.trim().length()<1) continue;
	        Symbol br = new Symbol();
	        br.setKind(Symbol.Category.BRANCH);
	        br.setOriginal(str);
	        feature.getBr().add(br);
	      }

	    String effect = tmp.get("effect");
	    if(effect != null && !"".equals(effect.trim()))
	    for (String str : effect.split("#")) {
		      str = str.replace(" ", "");
	      if(str.trim().length()<1) continue;
	      Symbol ef = new Symbol();
	      ef.setKind(Symbol.Category.EFFECT);
	      ef.setOriginal(str);
	      feature.getEf().add(ef);
	    }
		// TODO Auto-generated method stub
		
	}

}
